/*
 * FiltroVentas_VentasPeriodoPane.java
 *
 * Created on 14 de marzo de 2007, 04:11 PM
 */

package inc.jmc.cyberboard.ui.ventas.common;

import inc.jmc.cyberboard.common.DefaultLookAndFeel;
import inc.jmc.jcalendarchooser.JCalendarChooser;
import java.awt.Insets;
import java.util.Date;
import java.util.Locale;
/**
 *
 * @author  JOlguin01
 */
public class FiltroVentas_VentasPeriodoPane extends javax.swing.JPanel {
    
    /** Creates new form FiltroVentas_VentasPeriodoPane */
    JCalendarChooser calendar1 ;
    JCalendarChooser calendar2 ;
    public FiltroVentas_VentasPeriodoPane(Locale locale) {
        initComponents();
        exe1.setMargin(new Insets(0,0,0,0));
        exe2.setMargin(new Insets(0,0,0,0));
        getInidateTxt().setBackground(DefaultLookAndFeel.NotEnabledTextBackground);
        getFindateTxt().setBackground(DefaultLookAndFeel.NotEnabledTextBackground);
        jPanel1.remove(jLabel3);
        calendar1 = new JCalendarChooser(new Date(),locale);
        calendar1.setBounds(10, 90, 170, 145);
        calendar1.setTextField(getInidateTxt());///aqui definimos el textfield donde se tiene que quedar la fecha seleccionada
        calendar1.setHideWhenDateSelected(true);
        jPanel1.add(calendar1);
        calendar1.setVisible(false);
        calendar2 = new JCalendarChooser(new Date(),locale);
        calendar2.setBounds(10, 90, 170, 145);
        calendar2.setTextField(getFindateTxt());///aqui definimos el textfield donde se tiene que quedar la fecha seleccionada
        calendar2.setHideWhenDateSelected(true);
        jPanel1.add(calendar2);
        calendar2.setVisible(false);
        this.updateUI();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        inidateTxt = new javax.swing.JTextField();
        exe1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        findateTxt = new javax.swing.JTextField();
        exe2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Periodo de ventas"));
        jLabel1.setText("<html>Fecha incial<BR>dd/mm/yyyy</html>");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(10, 20, 70, 30);

        inidateTxt.setEditable(false);
        jPanel1.add(inidateTxt);
        inidateTxt.setBounds(90, 30, 80, 19);

        exe1.setText(">");
        exe1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exe1ActionPerformed(evt);
            }
        });

        jPanel1.add(exe1);
        exe1.setBounds(180, 30, 20, 23);

        jLabel2.setText("<html>Fecha final<br>dd/mm/yyyy</html>");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(10, 60, 70, 30);

        findateTxt.setEditable(false);
        jPanel1.add(findateTxt);
        findateTxt.setBounds(90, 70, 80, 19);

        exe2.setText(">");
        exe2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exe2ActionPerformed(evt);
            }
        });

        jPanel1.add(exe2);
        exe2.setBounds(180, 70, 20, 23);

        jLabel3.setText("jLabel3");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(10, 90, 170, 120);

        add(jPanel1, java.awt.BorderLayout.CENTER);

    }// </editor-fold>//GEN-END:initComponents

    private void exe2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exe2ActionPerformed

        calendar2.setVisible(true);
        this.updateUI();
    }//GEN-LAST:event_exe2ActionPerformed

    private void exe1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exe1ActionPerformed

        calendar1.setVisible(true);
        this.updateUI();
    }//GEN-LAST:event_exe1ActionPerformed
    
    public boolean fechasvalidas()
    {
        String ini = getInidateTxt().getText();
        String fin = getFindateTxt().getText();
        if(ini.equals("") || fin.equals(""))
            return false;
        String auxini = ini.split("/")[2]+ini.split("/")[1]+ini.split("/")[0];
        String auxfin = fin.split("/")[2]+fin.split("/")[1]+fin.split("/")[0];
        int iniint = Integer.parseInt(auxini);
        int finint = Integer.parseInt(auxini);
        return iniint<=finint;
    }

    public javax.swing.JTextField getFindateTxt() {
        return findateTxt;
    }

    public javax.swing.JTextField getInidateTxt() {
        return inidateTxt;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton exe1;
    private javax.swing.JButton exe2;
    private javax.swing.JTextField findateTxt;
    private javax.swing.JTextField inidateTxt;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    
}
